package com.android.semita;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DatabaseHelper extends SQLiteOpenHelper {

	 public static final String DATABASE_NAME = "semita.db";
	 public static final String DATABASE_TABLE = "MESSENGER_LOCATION";
	 public static final int DATABASE_VERSION = 1;
	 
	 public static final String KEY_ID = "ID";	 
	 public static final String KEY_MESSENGER = "MESSENGER_ID";
	 public static final String KEY_INVOICE = "INVOICE_NO";	 	 
	 public static final String KEY_STARTTIME = "START_TIME";
	 public static final String KEY_UPDATELOCATION = "UPDATE_LOCATION";	 
	 public static final String KEY_UPDATETIME = "UPDATE_TIME";
	 
	 public DatabaseHelper(Context context) {
		 super(context, DATABASE_NAME, null, DATABASE_VERSION);
	 }
	
	// SQL Statement to create a new database.
	private static final String DATABASE_CREATE = "create table " + 
	DATABASE_TABLE + " (" + KEY_ID + " integer primary key autoincrement, " +
	KEY_MESSENGER + " interger not null, " +
	KEY_INVOICE + " varchar(50) not null, " +
	KEY_STARTTIME + " timestamp not null, " + 
	KEY_UPDATELOCATION + " text not null, " +
	KEY_UPDATETIME + " timestamp not null);";
	
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(DATABASE_CREATE);
	}
	
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w("DBAdapter", "Upgrading from version " + 
		              oldVersion + " to " +
		              newVersion + ", which will destroy all old data");
		
		// Drop the old table.
		db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
		// Create a new one.
		onCreate(db);
	}	
}
